<template>
	<view>
		<u-notify ref="uNotify"></u-notify>
		<u-picker 
		    :show="show" 
			@confirm="confirm" 
			:columns="columns" 
			:closeOnClickOverlay = "true"
			@close="show=false"
			@cancel="show=false" 
			keyName="label"></u-picker>
		<u-picker 
		    :show="showClient" 
			@confirm="confirmClient" 
			:columns="colClient" 
			:closeOnClickOverlay = "true"
			@close="showClient=false"
			@cancel="showClient=false" 
			keyName="label"></u-picker>
		<u-datetime-picker 
		    ref="datetimePicker" 
			:show="showTime" 
			v-model="times" 
			mode="datetime" 
			:minDate="minDate" 
			:maxDate="maxDate"
		    :closeOnClickOverlay = "true" 
			@close="showTime=false" 
			@cancel="showTime=false" 
			@confirm="pickerConfirm"
			:formatter="formatter"></u-datetime-picker>
		<view class="pagesTop">
			<view style="padding: 80rpx 0;">
				<u-steps :current="current" dot inactiveColor="#ffffff" activeColor="#59D441">
					<u-steps-item title="填写订单"></u-steps-item>
					<u-steps-item title="在线支付"></u-steps-item>
					<u-steps-item title="陪诊服务"></u-steps-item>
					<u-steps-item title="服务完成"></u-steps-item>
				</u-steps>
			</view>
			<view class="addForm">
				<view class="formBox padingno">
					<u-cell-group :border="false">
						<u-cell title="服务类型" :value="FormData.caseName"></u-cell>
					</u-cell-group>
				</view>
				<view class="formBox" style="margin-top: 40rpx;">
					<u--form :model="FormData" ref="FormData" :rules="rules" labelWidth=100>
						<u-form-item @click="show=true" label="选择医院" prop="Hos" borderBottom>
							<u-input v-model="FormData.Hos" border="none" placeholder="请选择" inputAlign="right" readonly></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item label="科室" prop="adoffice" borderBottom>
							<u-input v-model="FormData.adoffice" border="none" placeholder="请输入科室" inputAlign="right"></u-input>
						</u-form-item>
						<u-form-item @click="showTime=true" label="期望就诊时间" prop="seasTime" borderBottom>
							<u-input v-model="FormData.seasTime" border="none" placeholder="请选择" inputAlign="right" readonly></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item @click="showClient=true" label="就诊人" prop="client" borderBottom>
							<u-input v-model="FormData.client" border="none" placeholder="请选择" inputAlign="right" readonly></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item label="联系人" prop="contact" borderBottom>
							<u-input v-model="FormData.contact" border="none" placeholder="请输入联系人姓名" inputAlign="right"></u-input>
						</u-form-item>
						<u-form-item label="手机号码" prop="contactNumber" borderBottom>
							<u-input v-model="FormData.contactNumber" border="none" placeholder="请输入联系人号码" inputAlign="right" type="number"></u-input>
						</u-form-item>
						<u-form-item label="性别" prop="pesSex" borderBottom labelWidth="50%">
							<view class="radioGrp">
								<u-radio-group v-model="FormData.pesSex" placement="row" activeColor="#0782C9">
									<view class="radioList radList1">
										<u-radio label="不限" :customStyle="{marginRight: '20rpx'}" :name="2"></u-radio>
									</view>
									<view class="radioList radList2">
										<u-radio label="男" :customStyle="{marginRight: '20rpx'}" :name="1"></u-radio>
									</view>
									<view class="radioList radList3">
										<u-radio label="女" :customStyle="{marginRight: '20rpx'}" :name="0"></u-radio>
									</view>
								</u-radio-group>
							</view>
						</u-form-item>
						<u-form-item label="要求" prop="svsLeave" labelWidth=60>
							<u--textarea v-model="FormData.svsLeave" placeholder="请输入您的服务要求" count height=120></u--textarea>
						</u-form-item>
					</u--form>
				</view>
			</view>
		</view>
		<view class="addfoot">
			<view style="margin: 20rpx 0 0 40rpx">
				<u-checkbox-group @change="checkboxChange">
					<view>
						<u-checkbox :checked="checked" shape="circle" activeColor="#0782C9"></u-checkbox>
					</view>
					<view style="font-size: 28rpx;">
						我已阅读同意
						<text style="color: #0782C9;">《服务条款同意书》</text>
					</view>
				</u-checkbox-group>
			</view>
			<view class="addBtn" @click="submit">立即下单</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false,
				current:0,
				FormData: {
					caseName: '一对一专业陪诊（半天陪诊）',
					svsLeave:'',
					pesSex: 2
				},
				show: false,
				showTime: false,
				showClient: false,
				times: Number(new Date()),
				minDate: Date.now(),
				maxDate: (new Date(new Date().getFullYear()+1,11,31,23,59)).getTime(),
				columns: [
					[{
							label: '湘雅一医院',
							id: 1
						},
						{
							label: '湘雅二医院',
							id: 2
						},
						{
							label: '湘雅三医院',
							id: 3
						},
					]
				],
				colClient: [
					[{
							label: '丰子恺',
							id: 1
						},
						{
							label: '丰子琪',
							id: 2
						}
					]
				],
				rules: {
					Hos: [{
						type: 'string',
						required: true,
						message: '请选择医院',
						trigger: ['blur', 'change']
					}],
					seasTime: [{
						type: 'string',
						required: true,
						message: '请选择期望就诊时间',
						trigger: ['blur', 'change']
					}],
					client: [{
						type: 'string',
						required: true,
						message: '请选择就诊人',
						trigger: ['blur', 'change']
					}],
					contact: [{
						type: 'string',
						required: true,
						message: '请输入联系人',
						trigger: ['blur', 'change']
					}],
					contactNumber: [{
						type: 'string',
						required: true,
						message: '请输入联系人号码',
						trigger: ['blur', 'change']
					}],
				}
			}
		},
		onReady() {
			// 微信小程序需要用此写法
			let time = new Date(new Date().getFullYear()+1,11,12,23,59);
			this.$refs.datetimePicker.setFormatter(this.formatter)
		},
		methods: {
			onNotify(type,msg) {
				this.$refs.uNotify.show({
					type: type,
					message: msg,
					duration: 1000 * 3
				})
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				if (type === 'hour') {
					return `${value}时`
				}
				if (type === 'minute') {
					return `${value}分`
				}
				return value
			},
			confirm(e) {
				this.FormData.Hos = e.value[0].label;
				this.show = false;
			},
			confirmClient(e) {
				this.FormData.client = e.value[0].label;
				this.showClient = false;
			},
			pickerConfirm(e){
				let timeValue = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM');
				this.FormData.seasTime = timeValue;
				this.showTime = false;
			},
			checkboxChange() {
				this.checked = !this.checked;
				console.log(this.checked);
			},
			submit() {
				console.log(this.FormData);
				this.$refs.FormData.validate().then(res => {
					this.onNotify('success','校验通过');
					uni.navigateTo({
						url:'/subpages/pages-service/pay/payOrder'
					})
				}).catch(errors => {
			        this.onNotify('error','校验失败');
				})
			},
		}
	}
</script>

<style lang="scss">
	body {
		background-color: $uni-bg-color-grey;
	}

	.pagesTop {
		width: 100%;
		height: 300rpx;
		background: linear-gradient(to left, $uni-aicloud, $uni-aicloud-gradation);
		font-size: 28rpx;
		color: #ffffff;
	}

	.u-steps-item__wrapper.data-v-3ae6176e {
		background-color: hsla(0, 0%, 100%, 0) !important;
		/* 完全透明 */
	}

	.u-text__value--main.data-v-50004b49,
	.u-text__value--content.data-v-50004b49 {
		color: #ffffff !important;
	}

	.addForm {
		padding: 20rpx;
		padding-bottom: 200rpx;
	}

	.formBox {
		background: #ffffff;
		border-radius: 10rpx;
		overflow: hidden;
		margin-bottom: 20rpx;
		box-shadow: 3rpx 3rpx 6rpx 0 #D3D0D0;
		padding: 0 30rpx;
	}
	.padingno{
		padding: 0;
	}

	.u-form-item__body__right__message.data-v-067e4733 {
		text-align: right;
	}
    .radioGrp{
		width: 50%;
		float: right;
		position: relative;
		margin-bottom: 10%;
	}
	.radioList{
		position: absolute;
	}
	.radList1{
		right: 20rpx;
	}
	.radList2{
		right: -80rpx;
	}
	.radList3{
		right: -180rpx;
	}
	.addfoot {
		position: fixed;
		bottom: 0;
		width: 100%;
		box-shadow: 0 -5rpx 10rpx #D3D0D0;
		background: #ffffff;
	}

	.addBtn {
		width: 90%;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		background: linear-gradient(to left, $uni-aicloud, $uni-aicloud-gradation);
		color: #ffffff;
		font-size: 28rpx;
		border-radius: 80rpx;
		margin: 30rpx auto;

	}
</style>